/**
 * 关联持仓
 * 2022-12-07
 */
import React from 'react';
import { connect } from 'dva';
import { ModalC, TableC } from '../../../../comps';
class ViewModaC extends React.Component {
  constructor(props) {
    super(props);
    this.state = {
      columns: [], // 表格头
      dataSource: [], // 表格数据
      current: 1,
      pageSize: 10,
      total: 0,
    };
  }

  componentDidMount() {
    this.getTableData();
  }
  //获取表格数据
  getTableData = () => {
    const {
      dispatch,
      relatedPositionM: { currentColumns },
      modalData,
      cpCode,
      record,
    } = this.props;
    dispatch({
      type: 'tansactionRecordquiryM/queryFnd',
      payload: {
        cpCode: [modalData.portfolioId],
        page: 1,
        pageSize: 10,
        exchangeCode: modalData.exchangeCode,
        tradingCode: modalData.securitiesCode,
        type: record.assetTypeFB == 12 ? '8' : '7',
      },
      callback: (res) => {
        let newColumns = record.assetTypeFB == 7 ? currentColumns : currentColumns.filter((i) => i.key != 'dealFullPrice');
        if (res) {
          this.setState({
            columns: newColumns, // 表格头
            dataSource: res.data, // 表格数据
            total: res.total,
          });
        } else {
          this.setState({
            columns: newColumns, // 表格头
            dataSource: [], // 表格数据
          });
        }
      },
    });
  };

  // 取消
  onCancel = () => {
    this.props.onCancel();
  };

  //分页切换
  handleTableChange = (pagination) => {
    const { current, pageSize } = pagination;
    this.setState(
      {
        current: current,
        pageSize: pageSize,
      },
      () => {
        this.getTableData();
      },
    );
  };

  render() {
    const { loading, visible } = this.props;
    const { columns, dataSource, current, pageSize, total } = this.state;
    return (
      <div>
        <ModalC title={'查看'} visible={visible} maskClosable={false} onCancel={this.onCancel} width={1200} height={420} footer={null}>
          <TableC
            columns={columns || []}
            dataSource={dataSource || []}
            scroll={{ x: 1100, y: 320 }}
            loading={loading.effects['tansactionRecordquiryM/queryFnd']}
            rowKey={'key'}
            size={'small'}
            onChange={this.handleTableChange}
            current={current}
            pageSize={pageSize}
            total={total}
          />
        </ModalC>
      </div>
    );
  }
}
export default connect(({ relatedPositionM, loading }) => ({ relatedPositionM, loading }))(ViewModaC);
